# include<iostream>
#include <math.h>
#include <string>
#include <stdio.h>
using namespace std;                                                                  
//  

	

	void collectInput(double& first, double& second, double&third, double&fourth)				// Gathers user input
			{  double currentSavings, monthlyContribution, rateOfReturn, currentAge;

					
					 cout << "			Current Savings:	";
					 cin  >>currentSavings; 
					 first = currentSavings;
					 cout << "			Monthly Contributions:	";
					 cin  >>monthlyContribution; 
					 second = monthlyContribution; 
					 cout << "			Rate of Return:	";
					 cin  >>rateOfReturn;
					 third = rateOfReturn;
					 cout << "			Current Age:	";
					 cin  >>currentAge;
					 fourth = currentAge;
					 
					 cout <<endl<<endl;
					 
					
	}


	void calculateMillionaire(double savings, double contribution, double rate , double age)		// Find how long it takes to become a millionaire based on user input
															
		{	double interest, mInterest, var,d;
			double y;
			int counter;
			double counter2;

				interest = 1 + (rate/100);
				mInterest = pow(interest , 0.0833);
				d= savings;
				for (counter=0; counter<1200; counter++)
							{
									d= d * mInterest + contribution;
									if (d >= 1000000)
										break;		
							}
				if (d < 1000000 )
						{  cout<< "Sorry, at this rate you won't be a millionaire in the next hundred years."<<endl<<endl;
				
							}
					
				else
						{  counter2 = counter;

							y = floor(counter2/12);
							
							cout<<"At this rate, you will be a millionaire in "<<y<<" years and "<<(counter%12)<<" months. You are now "<<age<<", so you will be a millionaire by age "<<(age+y)<<"."<<endl<<endl;	
							}
				
			
				}
	
	

void iWantToBeAMillionaire()
{
  double currentSavings, monthlyContribution, rateOfReturn, currentAge;	
 											
	
  char useranswer;		
  bool question = true;
 
  
  cout << "******************** HOW LONG UNTIL YOU BECOME A MILLIONAIRE ********************"<<endl<<endl;    
   
  
  while(question)
		{
			currentSavings=0;
			monthlyContribution=0;
			rateOfReturn=0;
			currentAge=0;
			

			 collectInput(currentSavings, monthlyContribution, rateOfReturn, currentAge);               //Call user input function and assign values

			 calculateMillionaire(currentSavings, monthlyContribution, rateOfReturn, currentAge);		//User input to call money calculator
			
			
	cout <<"		Thanks for using our systems."<<endl;
	cout << "		Do you want to start over? (Y/N)"<<endl<<endl;     //User is asked to continue using the program or abort
				cin>>useranswer;
              
   if (useranswer != 'y' && useranswer !='Y')
   
		 { 
             cout <<"Thanks yor are all done"<<endl;  
             question = false;   
           }         
               
 }
                system ("PAUSE"); 
}
